package com.yisu.expressway.onedollar.widget.scrolltextview;

import java.util.List;

import com.yisu.expressway.R;
import com.yisu.expressway.main_page.model.HomeBannerObj;
import com.yisu.expressway.onedollar.model.NoticeItem;
import com.yisu.expressway.utils.SpannableUtil;

import android.content.Context;
import android.text.SpannableStringBuilder;
import android.util.AttributeSet;


/**
 * Created by Kaven on 2016/12/9.
 */

public class ScrollTextView extends BaseScrollTextView {
    public ScrollTextView(Context context) {
        super(context);
    }

    public ScrollTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public SpannableStringBuilder getItemText(List data, int position) {
        if(data.get(position) instanceof NoticeItem) {
            NoticeItem noticeItem = (NoticeItem) data.get(position);
            if (getResources().getString(R.string.one_dollar_notice_empty).equals(noticeItem.winningUserName)) {
                return SpannableUtil.setHighLight(getContext(), noticeItem.winningUserName, noticeItem.winningUserName, R.color.oneDollarTextGrey);
            } else {
                String source = String.format(getResources().getString(R.string.one_dollar_congr),
                        noticeItem.winningUserName, noticeItem.goodsName);
                String key = String.format(getResources().getString(R.string.one_dollar_congr_prefix),
                        noticeItem.winningUserName);
                return SpannableUtil.setHighLight(getContext(), source, key, R.color.oneDollarTextGrey);
            }
        }else {
            HomeBannerObj.NoticeItem homeNoticeItem = (HomeBannerObj.NoticeItem)data.get(position);
            return new SpannableStringBuilder(homeNoticeItem.title);
        }

    }

    @Override
    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        super.setOnItemClickListener(onItemClickListener);
    }
}
